/**
 * 
 */
package net.efo.view;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTree;
import javax.swing.tree.TreeNode;

import net.efo.model.TreeHierarchy;

import java.awt.*;

/**
 * @author johnydoe
 *
 */
public class MainView1 extends JFrame {

	private static final long serialVersionUID = -4000190934230593280L;
	private JScrollPane scrolltree;
	private JTree treeView;
	private TreeHierarchy root;
	
	private JPanel mainPanel;
	
	public MainView1(TreeHierarchy root) {
		this.root = root;
	}
	
	public void buildView() {
		Insets size = getMaximizedScreenSize();
		
		this.mainPanel = new JPanel(new GridLayout(1,0));
		this.mainPanel.setBounds(size.left, size.top, size.right, size.bottom);
		this.scrolltree = new JScrollPane(this.getTreeView());
		this.mainPanel.add(this.scrolltree);
		
		this.add(this.mainPanel);		
		this.setBounds(size.left, size.top, size.right, size.bottom);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setVisible(true);
	}
	
	private Insets getMaximizedScreenSize() {
		System.out.println("OS: " + System.getProperty("os.name"));
		Rectangle r = new Rectangle();
		Insets i = new Insets(0,0,0,0);
		for (GraphicsDevice gs : GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()) 
			for (GraphicsConfiguration gc : gs.getConfigurations()) {
				r = r.union(gc.getBounds());
				i = Toolkit.getDefaultToolkit().getScreenInsets(gc);
			}
		i.set(r.y + i.top, r.x + i.left, r.height - i.bottom, r.width - i.right);
		System.out.println("Your insets should be: " + i.toString());
		
		return i;
	}
	
	private JTree getTreeView() {
		if (this.treeView == null) {
			this.treeView = new JTree(this.root);
			this.treeView.setBounds(0, 0, 800, 800);
			this.treeView.setPreferredSize(new Dimension(300, 720));
		}
		return this.treeView;
	}

}
